<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\UX\Translator\Tests\Functional;

use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\UX\Translator\Tests\Kernel\FrameworkAppKernel;

class DumpEnabledLocalesTest extends KernelTestCase
{
    protected static function getKernelClass(): string
    {
        return FrameworkAppKernel::class;
    }

    public function testShouldDumpOnlyEnabledLocales()
    {
        self::assertFileExists(__DIR__.'/../Fixtures/translations/messages.en.yaml');
        self::assertFileExists(__DIR__.'/../Fixtures/translations/messages.fr.yaml');
        self::assertFileExists(__DIR__.'/../Fixtures/translations/messages.es.yaml');

        $enabledLocales = self::getContainer()->getParameter('kernel.enabled_locales');
        self::assertNotContains('es', $enabledLocales, 'The "es" locale should not be enabled in this test');

        $translationsDumpDir = self::getContainer()->getParameter('kernel.project_dir').'/var/translations';
        self::assertDirectoryExists($translationsDumpDir);

        self::assertStringEqualsFile(
            $translationsDumpDir.'/index.js',
            <<<JS
                // This file is auto-generated by the Symfony UX Translator. Do not edit it manually.

                export const localeFallbacks = {"en":null,"fr":"en"};
                export const messages = {
                    "symfony_ux.great": {"translations":{"messages":{"en":"Symfony UX is awesome","fr":"Symfony UX est g\u00e9nial"}}},
                };

                JS
        );
        self::assertStringEqualsFile(
            $translationsDumpDir.'/index.d.ts',
            <<<TS
                // This file is auto-generated by the Symfony UX Translator. Do not edit it manually.
                import { Message, NoParametersType, LocaleType } from '@symfony/ux-translator';

                export declare const localeFallbacks: Record<LocaleType, LocaleType>;
                export declare const messages: {
                    "symfony_ux.great": Message<{ 'messages': { parameters: NoParametersType } }, 'en'|'fr'>;
                };

                TS
        );
    }
}
